#include "graph.h"
#pragma GCC optimize(3, "unroll-loops", "no-stack-protector")
#define atsum(l, r) accumulate(l, r, 0)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void chkmin(T &x, T y) { x = min(x, y); }
template <typename T>
inline void chkmax(T &x, T y) { x = max(x, y); }
namespace{
const int N = 205;
int g[N][N], cnt = 1, fa[N], du[N];
int pw[5] = {1, 3, 9, 27, 81};
int type, buc[N], to[N][N];
bool im[N][N];
int info[N][N];
bool used[N][N];
vector<pair<int, int> > vec[N];
};
void dfs(int u) {
    if (fa[u]) im[u][g[u][fa[u]] = LastRoad()] = 1;
    du[u] = NumberOfRoads();
    for (int i = 1; i <= du[u]; i++) {
        Move(i, 2);
        if (Color() == 1) {
            im[u][i] = 1;
            int v = ++cnt;
            vec[u].emplace_back(v, i);
            fa[v] = u, g[u][v] = i, dfs(v);
            Move(g[v][u], 3);
        } else {
            assert(Color() != 1);
            if (Color() == 2) used[u][i] = 1;
            int c = Color();
            Move(LastRoad(), c);
        }
    }
}
// 1 3 9 27 81

void make(int u) {
    for (auto [v, id] : vec[u]) Move(id, (u / pw[type]) % 3 + 1), make(v);
    for (int i = 1; i <= du[u]; i++) if (!used[u][i] && !im[u][i]) {
        Move(i, (u / pw[type]) % 3 + 1);
        int c = Color();
        info[u][i] += (c - 1) * pw[type];
        Move(LastRoad(), c);
    }
    if (fa[u]) Move(g[u][fa[u]], (u / pw[type]) % 3 + 1);
}
void Inspect(int R) {
    dfs(1);
    // cerr << "find cnt:" << cnt << endl;
    int n = cnt;
    for (int i = 0; i < 5; i++) {
        type = i;
        make(1);
    }
    for (int u = 1; u <= n; u++)
        for (int v = 1; v <= du[u]; v++) if (!used[u][v] && !im[u][v]) g[u][info[u][v]] = g[info[u][v]][u] = 1;
    for (int u = 1; u <= n; u++) {
        for (int v = 1; v <= n; v++) {
            if (g[u][v]) g[u][v] = 1;
            else if (u == v) g[u][v] = 0;
            else g[u][v] = inf;
        }
    }
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) chkmin(g[i][j], g[i][k] + g[k][j]);
    for (int u = 1; u <= n; u++)
        for (int v = u + 1; v <= n; v++)
            if (g[u][v] <= n) ++ buc[g[u][v]];
    for (int i = 1; i <= R; i++) Answer(i, buc[i]);
}
